<php>
    if (!function_exists('_parse_vars')) {
    function _parse_vars($vars,$inputName,$level=1,$widget='',$file_id=''){
</php>
<foreach name="vars" item="var" key="varName">
    <fieldset>
        <div class="mb-3">
            <present name="var.title">
                <label class="form-label">
                    {:lang($var.title)}
                    <notempty name="var.rule.require">
                        <span class="form-required">*</span>
                    </notempty>
                </label>
            </present>
            <php>$placeholder=empty($var['placeholder'])?'':$var['placeholder'];</php>
            <switch name="var.type">
                <case value="text">
                    <div class="controls">
                        <present name="var.dataSource">
                            <input type="text" name="{$inputName}[{$varName}_text_]" class="form-control"
                                onclick="doSelectData(this)"
                                data-source="{:base64_encode(json_encode($var['dataSource']))}"
                                data-title="请选择{:lang($var.title)}" value="{$vars[$varName]['valueText']|default=''}"
                                placeholder="{:lang($placeholder)}">
                            <input type="hidden" name="{$inputName}[{$varName}]" class="form-control"
                                value="{$vars[$varName]['value']}">
                            <else />
                            <input type="text" name="{$inputName}[{$varName}]" class="form-control"
                                value="{$vars[$varName]['value']}" placeholder="{:lang($placeholder)}">
                        </present>
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="textarea">
                    <div class="controls">
                        <textarea name="{$inputName}[{$varName}]" class="form-control"
                            placeholder="{:lang($placeholder)}">{$vars[$varName]['value']}</textarea>
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="date">
                    <div class="controls">
                        <input type="text" name="{$inputName}[{$varName}]" class="form-control js-bootstrap-date"
                            value="{$vars[$varName]['value']}" placeholder="{:lang($placeholder)}">
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="datetime">
                    <div class="controls">
                        <input type="text" name="{$inputName}[{$varName}]" class="form-control js-bootstrap-datetime"
                            value="{$vars[$varName]['value']}" placeholder="{:lang($placeholder)}">
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="image">
                    <div class="controls">
                        <input type="hidden" name="{$inputName}[{$varName}]" class="form-control"
                            value="{$vars[$varName]['value']}" id="js-{$widget}{$varName}-input">
                        <div>
                            <a href="javascript:doUploadOneImage('{:lang('Upload Image')}','#js-{$widget}{$varName}-input');">
                                <if condition="empty($vars[$varName]['value'])">
                                    <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                        id="js-{$widget}{$varName}-input-preview" width="135" style="cursor: pointer" />
                                    <else />
                                    <img src="{:cmf_get_image_preview_url($vars[$varName]['value'])}"
                                        id="js-{$widget}{$varName}-input-preview" width="135" style="cursor: pointer" />
                                </if>
                            </a>
                            <if condition="!empty($vars[$varName]['value'])">
                                <br>
                                <button id="js-{$widget}{$varName}-button-remove"
                                    defaultImage="__TMPL__/public/assets/images/default-thumbnail.png"
                                    class="removeImage btn btn-sm" type="button"
                                    onclick="removeImage('{$widget}{$varName}')">{:lang('Cancel')}
                                </button>
                            </if>
                        </div>
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="image2">
                    <style>
                        
                    </style>
                    <php>
                        $image_url = $vars[$varName]['value'];
                        $preview_style = empty($vars[$varName]['value']) ? 'display:none;' : '';
                    </php>
                    <div class="controls">
                        <input type="hidden" name="{$inputName}[{$varName}]" class="form-control" value="{$image_url}" id="js-{$widget}{$varName}-input">
                        <div class="image-div">
                            <a href="javascript:doUploadOneImage2('{:lang('Upload Image')}','#js-{$widget}{$varName}');">
                                <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                    id="js-{$widget}{$varName}-img-upload" width="135" height="135" class="upload-img" />
                            </a>
                            <div id="js-{$widget}{$varName}-div-preview" class="preview-div" style="{$preview_style}">
                                <a href="">
                                    <img src="{:cmf_get_image_preview_url($image_url)}"
                                        id="js-{$widget}{$varName}-img-preview" width="135" height="135"
                                        style="cursor: pointer" />
                                </a>
                                <div class="mask">
                                    <div style="left: 50%; text-align: center; margin-top: 35%;">
                                        <button type="button" class="btn btn-info js-ajax-submit"
                                            onclick="parent.imagePreviewDialog('{:cmf_get_image_preview_url($image_url)}');">
                                            <i class="fa fa-search-plus"></i>
                                        </button>                                        
                                        <button id="js-{$widget}{$varName}-button-remove" type="button" class="removeImage btn btn-danger js-ajax-submit" 
                                            onclick="removeImage2('{$widget}{$varName}')">
                                            <i class="fa fa-trash-o"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </case>
                <case value="number">
                    <div class="controls">
                        <input type="number" name="{$inputName}[{$varName}]" class="form-control"
                            value="{$vars[$varName]['value']}" placeholder="{:lang($placeholder)}">
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="location">
                    <div class="controls">
                        <input type="text" name="{$inputName}[{$varName}_text_]" class="form-control"
                            onclick="doSelectLocation(this)" data-title="请选择{:lang($var.title)}"
                            value="{$vars[$varName]['valueText']|default=''}" placeholder="{:lang($placeholder)}">
                        <input type="hidden" name="{$inputName}[{$varName}]" class="form-control"
                            value="{$vars[$varName]['value']}">
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="file">
                    <div class="controls">
                        <div class="input-group">
                            <input type="text" name="{$inputName}[{$varName}]" class="form-control"
                                value="{$vars[$varName]['value']}" id="js-{$widget}{$varName}-input-file"
                                placeholder="{:lang($placeholder)}">
                            <span class="input-group-addon"> <a
                                    href="javascript:doUploadOne('{:lang('Upload Image')}','#js-{$widget}{$varName}-input-file','file');">{:lang('Upload
                                    Image')}</a></span>
                        </div>
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="color">
                    <div class="controls">
                        <input type="text" name="{$inputName}[{$varName}]" class="form-control js-color"
                            value="{$vars[$varName]['value']}" id="js-color-{$widget}{$varName}"
                            placeholder="{:lang($placeholder)}">
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>

                <case value="array">
                    <div class="controls">
                        <php>
                            $arrayValueText=is_array($var['value'])&&count($var['value'])>0?count($var['value']).'条数据,点击添加更多...':'';
                        </php>
                        <textarea class="form-control" placeholder="" onclick="doEditArrayData(this)"
                            data-var="{$varName}" data-widget="{$widget}" data-title="{$var.title}"
                            data-file_id="{$file_id}">{$arrayValueText}</textarea>
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="select">
                    <div class="controls">
                        <php>
                            $value= $vars[$varName]['value'];
                            $options = $vars[$varName]['options'];
                        </php>
                        <select name="{$inputName}[{$varName}]" class="form-control">
                            <foreach name="options" item="optionItem" key="optionKey">
                                <php>$optionSelected=$optionKey==$value?"selected":"";</php>
                                <option value="{$optionKey}" {$optionSelected}>{:lang($optionItem)}
                                </option>
                            </foreach>
                        </select>
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="slide">
                    <div class="controls">
                        <input type="text" name="{$inputName}[{$varName}]" class="form-control"
                            value="{$vars[$varName]['value']}">
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
                <case value="rich_text">
                    <div class="controls">
                        <div>
                            <script type="text/plain" class="rich_text_content"
                                name="{$inputName}[{$varName}]">{$vars[$varName]['value']}</script>
                        </div>
                        <present name="var.tip">
                            <div class="form-text">{:lang($var.tip)}</div>
                        </present>
                    </div>
                </case>
            </switch>
        </div>
    </fieldset>
</foreach>

<php>
    }
    }
</php>